package com.bysj.lms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bysj.lms.pojo.entity.LmsFa;
import com.bysj.lms.pojo.entity.LmsLve;
import com.bysj.lms.mapper.LmsLveMapper;
import com.bysj.lms.service.ILmsLveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class LmsLveServiceImpl extends ServiceImpl<LmsLveMapper, LmsLve> implements ILmsLveService {

    @Autowired
    LmsLveMapper lmsLveMapper;

    @Override
    public PageInfo findByPage(String name, int page, int count) {

        PageHelper.startPage(page,count);
        List<LmsLve> list = lmsLveMapper.list(name);
        return new PageInfo(list);
    }

    @Override
    public boolean isExist(String instruNumber) {
        QueryWrapper<LmsLve> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("instru_number",instruNumber);
        LmsLve lmsLve = lmsLveMapper.selectOne(queryWrapper);
        if(lmsLve!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean bind(String number, Integer rid) {

        boolean update = lambdaUpdate().eq(LmsLve::getInstruNumber,number).set(LmsLve::getRoomId,rid).update();
        return update;
    }

    @Override
    public boolean binds(List<String> numbers, String rid) {
        int binds = lmsLveMapper.binds(numbers,rid);
        return binds>0?true:false;
    }

    @Override
    public boolean adds(List<LmsLve> lmsLves) {
        int adds = lmsLveMapper.adds(lmsLves);
        return adds==0?false:true;
    }

    @Override
    public void changeStatus(String status, String number) {
        lambdaUpdate().set(LmsLve::getStatus,status)
                .eq(LmsLve::getInstruNumber,number).update();
    }
}
